package com.wkhyapp.lm.contract;

import com.wkhyapp.lm.base.BasePresenter;
import com.wkhyapp.lm.http.ApiCallback;
import com.wkhyapp.lm.http.net.BaseRequest;
import com.wkhyapp.lm.http.net.GoodsInfoRequest;
import com.wkhyapp.lm.http.net.GoodsListRequest;
import com.wkhyapp.lm.http.net.RefreshGoodsRequest;
import com.wkhyapp.lm.http.net.SuperResponse;
import com.wkhyapp.lm.http.vo.Goods;
import com.wkhyapp.lm.utils.MemberUtils;

import java.util.List;

/**
 * Created by Administrator on 2021-10-6.
 */

public class XiangCePresenter extends BasePresenter<XiangCeView> {

    public XiangCePresenter(XiangCeView xiangCeView) {
        super(xiangCeView);
    }
    public void getData(String key){
        GoodsListRequest request = new GoodsListRequest();
        request.setUserId(MemberUtils.getUid());
        request.setPageNo(1);
        request.setPageSize(30);
        request.setKey(key);
        addSubscription(apiStores.shopGoodsList(request),new ApiCallback<SuperResponse<Goods>>() {
            @Override
            public void onSuccess(SuperResponse<Goods> response) {
                mvpView.setGoods(response.getItems());
            }
            @Override
            public void onFailure(String msg) {
            }
            @Override
            public void onFinish() {
                mvpView.dismissLoad();
            }
        });

    }

    public void getDataMore(int pageNo,String key){
        GoodsListRequest request = new GoodsListRequest();
        request.setUserId(MemberUtils.getUid());
        request.setPageNo(pageNo);
        request.setKey(key);
        request.setPageSize(30);
        addSubscription(apiStores.shopGoodsList(request),new ApiCallback<SuperResponse<Goods>>() {
            @Override
            public void onSuccess(SuperResponse<Goods> response) {
                mvpView.setGoodsMore(response.getItems());
            }
            @Override
            public void onFailure(String msg) {
            }
            @Override
            public void onFinish() {
                mvpView.dismissLoad();
            }
        });
    }


    public void delete(Long goodsId){
        GoodsInfoRequest request = new GoodsInfoRequest();
        request.setUserId(MemberUtils.getUid());
        request.setGoodsId(goodsId);
        addSubscription(apiStores.delGoods(request),new ApiCallback<SuperResponse<String>>() {
            @Override
            public void onSuccess(SuperResponse<String> response) {
                mvpView.setSucc("删除成功");
            }
            @Override
            public void onFailure(String msg) {
            }
            @Override
            public void onFinish() {
                mvpView.dismissLoad();
            }
        });
    }

    public void setUp(Long goodsId){
        GoodsInfoRequest request = new GoodsInfoRequest();
        request.setUserId(MemberUtils.getUid());
        request.setGoodsId(goodsId);
        addSubscription(apiStores.setUp(request),new ApiCallback<SuperResponse<String>>() {
            @Override
            public void onSuccess(SuperResponse<String> response) {
                mvpView.setSucc("设置成功");
            }

            @Override
            public void onFailure(String msg) {
            }

            @Override
            public void onFinish() {
                mvpView.dismissLoad();
            }
        });
    }


    public void refreshGoods(List<Long> ids){
        RefreshGoodsRequest request = new RefreshGoodsRequest();
        request.setUserId(MemberUtils.getUid());
        request.setIds(ids);
        addSubscription(apiStores.refreshGoods(request),new ApiCallback<SuperResponse<String>>() {
            @Override
            public void onSuccess(SuperResponse<String> response) {
                mvpView.setSucc(response.getMessage());
            }
            @Override
            public void onFailure(String msg) {
            }
            @Override
            public void onFinish() {
                mvpView.dismissLoad();
            }
        });
    }


    public void clearXC(){
        BaseRequest request = new BaseRequest();
        request.setUserId(MemberUtils.getUid());
        addSubscription(apiStores.clearAlbumAddr(request),new ApiCallback<SuperResponse<String>>() {
            @Override
            public void onSuccess(SuperResponse<String> response) {
                mvpView.setSucc("相册地址已清理");
            }
            @Override
            public void onFailure(String msg) {
            }
            @Override
            public void onFinish() {
                mvpView.dismissLoad();
            }
        });
    }

}
